//
//  LNViewModel.m
//  LNBeeHive
//
//  Created by wwww on 2019/9/30.
//  Copyright © 2019 淘发现1iOS. All rights reserved.
//

#import "LNViewModel.h"

@interface LNViewModel()
// 参数
@property (nonatomic, readwrite, copy) NSDictionary *params;
// 统一错误处理
@property (nonatomic, readwrite, strong) RACSubject *errors;
@end

@implementation LNViewModel
/// when `BaseViewModel` created and call `initWithParams` method , so we can ` initialize `
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    LNViewModel *viewModel = [super allocWithZone:zone];
    @weakify(viewModel)
    [[[viewModel
       rac_signalForSelector:@selector(initWithParams:)] delay:2]  subscribeNext:^(id x) {
        @strongify(viewModel)
        [viewModel initialize];
    }];
    return viewModel;
}

/// create `viewModel` instance
- (instancetype)initWithParams:( nullable NSDictionary *)params {
    self = [super init];
    if (self) {
        self.params   = params;
    }
    return self;
}


- (RACSubject *)errors {
    if (!_errors) _errors = [RACSubject subject];
    return _errors;
}

/// sub class can override
- (void)initialize {
    
}

-(void)dealloc{
    
    NSLog(@"%@viewModel销毁",self.title);
}
@end
